﻿#region File Description
//LineSegment.cs
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
#endregion

namespace Squog_1._1
{
    public class LineSegment
    {
        #region Members

        private Vector2 direction;
        private Vector2 startPoint, endPoint;

        #endregion

        #region Initilization

        public LineSegment(Vector2 startPoint, Vector2 endPoint)
        {
            this.startPoint = startPoint;
            this.endPoint = endPoint;
        }

        public LineSegment(float startPointX, float startPointY, float endPointX, float endPointY)
            : this(new Vector2(startPointX, startPointY), new Vector2(endPointX, endPointY))
        {

        }


        #endregion

        #region Accessors

        public Vector2 NormalVector
        {
            get
            {
                return Vector2.Normalize(new Vector2(-(endPoint.Y - startPoint.Y), (endPoint.X - startPoint.X)));
            }
        }

        public Vector2 MidPoint
        {
            get
            {
                return new Vector2(((startPoint.X + endPoint.X) / 2), ((startPoint.Y + endPoint.Y) / 2));
            }
        }

        public Vector2 Direction
        {
            get
            {
                direction = endPoint - startPoint;
                direction.Normalize();
                return direction;
            }
        }

        public float Length
        {
            get
            {
                return (float)Math.Sqrt(Math.Pow(startPoint.X - endPoint.X, 2) + Math.Pow(startPoint.Y - endPoint.Y, 2));
            }
        }

        public Vector2 point1
        {
            get
            {
                return startPoint;
            }
        }

        public Vector2 point2
        {
            get
            {
                return endPoint;
            }
        }

        #endregion
    }
}
